<?php
/**
 * 
 * 图片视图,只能使用系统提供的图片类库,phpimage,具体使用方法如下:
 * 
 * <code>
 * 	$response->view='imageView';
 *  $image   = new image();
 *  ......
 *  ......
 *  $data['image'] = $image;
 *  $data['type']= 'png'; //png|jpg|jpeg|gif中的一种
 *  $data['quality'] = 80;//0-100
 *  
 *  $response->assign($data);
 *  
 * </code>
 * @author LeoNing
 *
 */
class ImageView extends View {
	private $type = 'png';
	private $quality = 80;
	/**
	 * 要输出的图片
	 *
	 * @var image
	 */
	private $image = null;
	public function render($data, $response, $tpl = '') {
		extract ( $data );
		if (isset ( $image )) {
			$this->image = $image;
		}
		if (isset ( $type )) {
			$this->type = $type;
		}
		if (isset ( $quality ) && is_int ( $quality )) {
			$this->quality = $quality;
		}
		if ($this->image instanceof image) {
			switch ($this->type) {
				case 'gif' :
					$this->image->imageGif ();
					break;
				case 'jpg' :
				case 'jpeg' :
					$this->image->imageJpeg ( '', $this->quality );
					break;
				case 'png' :
				default :
					$this->image->imagePng ();
			}
			$this->image->destroyImage ();
		} else {
			trigger_error ( "no image instance specified!", E_USER_ERROR );
		}
	}
}